let a = {
    name: "nihao",
    age: 12
}

Object.defineProperty(a,"name",{
    configurable: false,
    value: "nihao",
    writable: false
})

Object.defineProperty(a,"age",{
    configurable: true,
    value: 12
})

delete a.name
delete a.age
console.log(a.name);

// Object.defineProperty(a,"name",{  // 无法多次定义name
//     configurable: true,
//     writable: true
// })

// delete a.name
a.name = "小红"
console.log(a.name);    // writable 控制属性是否可以被修改 为false时无法修改属性
console.log(a.age);     // age 被成功删除

let b = {
    year_: 2018,
    name: "你好",
    [Symbol.for("age")]:15
}
console.log(Object.getOwnPropertyNames(b))
console.log(b[Symbol.for("age")])

console.log("_____________________________________________")


let c = {
    name: {
        get(){
            return "123"
        },
        set(v){ 

        }
    }
}

delete c.name
console.log(c.name)

let des = Object.getOwnPropertyDescriptor(c,'name')
console.log(des);


let people = {
    name: "名",
    age: "性别",
    // sleep: function(){  // 正常写法
    //     console.log("睡觉")
    // }
    sleep(){  //简写
        console.log("睡觉")
    }
}

people.sleep()

function Person(name,age){
    if(!(this instanceof Person)){
        console.error("Person是一个构造函数必须使用new 方法构造");
        return 
    }
    
    this.name = name
    this.age = age
    this.sleep = function(){
        console.log("sleep")
    }

    console.log("打印",this);
}

Person('gang',15) // 这样调用当普通函数进行了一次调用